package com.project_task.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.project_task.dto.ProjectDTO;
import com.project_task.dto.ProjectPageQueryDTO;
import com.project_task.entity.Project;
import com.project_task.mapper.ProjectMapper;
import com.project_task.result.PageResult;
import com.project_task.service.ProjectService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProjectServiceImpl implements ProjectService {


    @Autowired
    private ProjectMapper projectMapper;

    /**
     * 创建项目
     * @param projectDTO
     */
    @Override
    public void save(ProjectDTO projectDTO) {
        // 创建项目
        Project project = new Project();
        BeanUtils.copyProperties(projectDTO, project);
        projectMapper.save(project);

    }

    /**
     * 项目分页查询
     * @param projectPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuery(ProjectPageQueryDTO projectPageQueryDTO) {
        PageHelper.startPage(projectPageQueryDTO.getPage(),projectPageQueryDTO.getPageSize());
        //下一条sql进行分页，自动加入limit关键字分页
        Page<Project> page = projectMapper.pageQuery(projectPageQueryDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }

}
